﻿using PHMEE.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using System.Linq.Expressions;

namespace PHMEE
{
    public class BaseRepository<TEntity, TKey> : EfCoreRepository<PHMEEDbContext, TEntity, TKey>, IBaseRepository<TEntity, TKey>
    where TEntity : class, IEntity<TKey>
    {
        public BaseRepository(IDbContextProvider<PHMEEDbContext> dbContextProvider)
            : base(dbContextProvider)
        {
        }

        public async Task<TEntity> PhmeeCreate(TEntity entity, bool autoSave = false)
        {
            return await InsertAsync(entity, autoSave);
        }

        public async Task PhmeeCreateMany(IEnumerable<TEntity> entities, bool autoSave = true)
        {
            await InsertManyAsync(entities, autoSave);
        }

        public async Task PhmeeDelete(TKey id, bool autoSave = false)
        {
            await DeleteAsync(id, autoSave);
        }

        public async Task<List<TEntity>> PhmeeGetAll()
        {
            return await GetListAsync();
        }

        public async Task<TEntity> PhmeeGetById(TKey id)
        {
            return await GetAsync(id);
        }

        public async Task<TEntity> PhmeeUpdate(TEntity entity, bool autoSave = false)
        {
            return await UpdateAsync(entity, autoSave);
        }

        public async Task<IQueryable<TEntity>> PhmeeGetQuery()
        {
            return await GetQueryableAsync();
        }

    }

}
